<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/questionnaire/approvelist">已审核</a></li>
		</ol>
	</section>
	<section class="content">
		<form action="${ctx}/questionnaire/approvedlist" method="get">
			<div class="box">
				<div class="box-header">
					<div class="row">
						<div class="col-sm-9">
							<div class="col-sm-2" style="width: 33%;">
								<input name="keyword" type="text" class="form-control" value="${keyword!}" placeholder="公司名称/话术名称" />
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-default btn-search" onclick="query()" value="查询" />
							</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>代理商</th>
								<th>公司</th>
								<th>话术名称</th>
								<th>类型</th>
								<th>提交时间</th>
								<th>当前状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as c>
							<tr>
								<td>${page.size * page.number+c_index+1}</td>
								<td>${c.agentsName!}</td>
								<td><a href="javascript:void(0);" onclick="viewCompany('${c.companyId!}')">${c.companyName!}</a></td>
								<td><a href="javascript:void(0);" onclick="toEdit('${c.companyId!}','${c.id!}','${c.scriptId!}')">${c.title!}</a></td>
								<#if c.industryType?? && dict["${c.industryType}"]?? >
									<td>${dict["${c.industryType}"]!}</td>
								<#else>
									<td></td>
								</#if>
								<td>${c.updateTime!}</td>
								<td>
									<#if c.dialogState?? && c.dialogState==3>
										已上线
									<#elseif c.dialogState?? && c.dialogState==4>
										已下线
									<#elseif c.dialogState?? && c.dialogState==5>
										已下线<a href="javascript:void(0);" onclick="viewReason('${c.id!}')">（原因）</a>
									<#else>
									</#if>
								</td>
								<td>
									<#-- <a href="javascript:void(0)" class="oper" onclick="loginfo('${c.id!}',this,'${c.companyName!}','${c.title!}')">操作日志</a> -->
									<a href="javascript:void(0)" class="oper" onclick="loginfo('${c.id!}','${c_index!}','${page.number!}')">操作日志</a>
									<#if c.dialogState?? && c.dialogState==3>
										<a href="javascript:void(0)" onclick="offline('${c.id!}')">下线</a>
									<#elseif c.dialogState?? && c.dialogState==4>
										<a href="javascript:void(0)" onclick="online('${c.id!}')">上线</a>
									<#elseif c.dialogState?? && c.dialogState==5>
										<a href="javascript:void(0)" onclick="online('${c.id!}')">上线</a>
									<#else>
									</#if>
								</td>
							</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</div>
		</form>
	</section>
</div>
<script type="text/javascript">
    sessionStorage.sum="${page.totalElements}"; //把每次查询到的数据放到sessionStorage，审批的时候上一条下一条要用到
	var win;
	var outPath = "${redirectUri}";
	var flag=0;
	//查询
	function query() {
		$(":input[name='pageNumber']").val(0);
		$("form").submit();
	}
	//编辑话术内容
	function toEdit(companyId,naireId,scriptId){
		var url = "${ctx}/login/sysOutLogin";
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : {"companyId":companyId},
			success : function(data) {
				if(data!=null){
					var sign = data.sign;
					var timestamps = data.timestamps;
					var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&naireId="+naireId+"&scriptId="+scriptId+"&requestType=questionnaire";
					if(win){
						win.close();
					}
					window.open(newUrl,"_blank");
				}else{
					bootbox.alert("跳转失败,请稍后重试!");
				}
			}
		});
	}

	//查看企业详情	
	function viewCompany(companyId){
		var url = "${ctx}/login/sysOutLogin";
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : {"companyId":companyId},
			success : function(data) {
				if(data!=null){
					var sign = data.sign;
					var timestamps = data.timestamps;
					var newUrl = outPath+"login/sysOutLogin.action?_clientType=wap&sign="+sign+"&timestamps="+timestamps+"&companyId="+companyId+"&requestType=index";
					if(win){
						win.close();
					}
					window.open(newUrl,"_blank");
				}else{
					bootbox.alert("跳转失败,请稍后重试!");
				}
			}
		});
	}

	//查看操作日志	
	var is_submit=false;
	function loginfo(id,obj,companyName,title){
		if(is_submit){
			return;
		}
		is_submit=true;
		$(".oper").css("color","#337ab7");
		$(obj).css("color","#AADCF8");
		var title = companyName+"-"+title;
		base.getView({
			url:"${ctx}/questionnaire/loginfo?id="+id,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function(){
								is_submit=false;
							}
						}
					}
				})
			}
		})
	}

    //审核方法
    function loginfo(id,index,page){
        var keyword=$("input[name='keyword']").val();
        window.location.href="${ctx}/questionnaire/loginfo?id="+id+"&index="+index+"&page="+page+"&from=已审核"+"&keyword="+keyword;
    }
	
	//上线
	function online(naireId){
		var url = "${ctx}/questionnaire/updateDialogState";
		var param = {
				"id":naireId,
				"dialogState":6//6代表管理员上线
			};
		$.ajax({
			url:url,
			type:'POST',
			data:param,
			dataType:'text',
			async:false,
			success:function(data){
				if(data=="success"){
					bootbox.alert("操作成功!",function(){
						window.location.reload();
					});
				}else{
					bootbox.alert("操作失败!");
				}
			}
		});
	}
	
	//审核驳回
	function offline(naireId){
		if(is_submit){
			return;
		}
		is_submit=true;
		var title = "下线";
		base.getView({
			url:"${ctx}/questionnaire/offlineForm?id="+naireId,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function(){
								if(flag){
									return false;
								}
								if($("#offlineForm").valid()) {
									flag=1;
									$.ajax({
										url:"${ctx}/questionnaire/updateDialogState",
										type:'POST',
										data:{
											"id":naireId,
											"dialogState":5,//5代表管理员下线
											"memo":$("#memo").val()
										},
										dataType:'text',
										async:false,
										success:function(data){	
											if(data=="success"){
												bootbox.alert("操作成功!",function(){
													window.location.reload();
												});
											}else{
												flag=0;
												bootbox.alert("操作失败!");
												is_submit=false;
											}
										},
										error:function(){
											flag=0;
										}
									});
								}
								return false;
							}
						}
					}
				})
			}
		});
	}
	
	function viewReason(naireId){
		if(naireId){
			$.ajax({
				url:"${ctx}/questionnaire/viewReason",
				type:'POST',
				data:{
					naireId:naireId
				},
				dataType:'text',
				async:false,
				success:function(data){
					if(data){
						bootbox.alert(data);
					}else{
						bootbox.alert("无");
					}
				}
			});
		}else{
			bootbox.alert("无");
		}
	}
</script>
<#include "../common/footer.htm">